<template>
  <div class="app-container">
    <!--<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="主表id" prop="parentId">
        <el-input
          v-model="queryParams.parentId"
          placeholder="请输入主表id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="序号" prop="xh">
        <el-input
          v-model="queryParams.xh"
          placeholder="请输入序号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="特殊工种证件" prop="tsgzzj">
        <el-input
          v-model="queryParams.tsgzzj"
          placeholder="请输入特殊工种证件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发证机关" prop="fzjg">
        <el-input
          v-model="queryParams.fzjg"
          placeholder="请输入发证机关"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件时效" prop="zjsx">
        <el-input
          v-model="queryParams.zjsx"
          placeholder="请输入证件时效"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证书编号" prop="zsbh">
        <el-input
          v-model="queryParams.zsbh"
          placeholder="请输入证书编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="初领证日期" prop="firstGetDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.firstGetDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择初领证日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="换证周期" prop="changeTerm">
        <el-input
          v-model="queryParams.changeTerm"
          placeholder="请输入换证周期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="复审周期" prop="validateTerm">
        <el-input
          v-model="queryParams.validateTerm"
          placeholder="请输入复审周期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上次复审日期" prop="lastValidateDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.lastValidateDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择上次复审日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="下次复审日期" prop="nextValidateDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.nextValidateDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择下次复审日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否过期" prop="expiredFlag">
        <el-input
          v-model="queryParams.expiredFlag"
          placeholder="请输入是否过期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->
    <el-row :gutter="10" class="mb8">
      <div style="font-size: 30px; text-align: center;margin-bottom: 0px;color: #ffffff;">特种设备作业类</div>
    </el-row>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
        <!-- v-hasPermi="['zyzs:info:add']" -->
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
          @click="handleUpdate">修改</el-button>
        <!-- v-hasPermi="['zyzs:info:edit']" -->
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
          @click="handleDelete">删除</el-button>
        <!-- v-hasPermi="['zyzs:info:remove']" -->
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zyzs:info:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" max-height="550" :data="infoList" :cell-style="cellStyle"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="序号" align="center" prop="id" /> -->
      <el-table-column label="姓名" align="center" prop="name" />
      <!-- <el-table-column label="部门" align="center" prop="deptName" /> -->
      <el-table-column label="特殊工种证件" align="center" prop="tsgzzj" />
      <el-table-column label="发证机关" align="center" prop="fzjg" />
      <el-table-column label="证件时效" align="center" prop="zjsx" />
      <el-table-column label="证书编号" align="center" prop="zsbh" />
      <el-table-column label="初领证日期" align="center" prop="firstGetDate">
        <template slot-scope="scope">
          <p>{{ parseTime(scope.row.firstGetDate, '{y}-{m}-{d}') }}</p>
        </template>
      </el-table-column>
      <el-table-column label="换证周期" align="center" prop="changeTerm" />
      <el-table-column label="复审周期" align="center" prop="validateTerm" />
      <el-table-column label="上次复审日期" align="center" prop="lastValidateDate">
        <template slot-scope="scope">
          <p>{{ parseTime(scope.row.lastValidateDate, '{y}-{m}-{d}') }}</p>
        </template>
      </el-table-column>
      <el-table-column label="下次复审日期" align="center" prop="nextValidateDate">
        <template slot-scope="scope">
          <p>{{ parseTime(scope.row.nextValidateDate, '{y}-{m}-{d}') }}</p>
        </template>
      </el-table-column>
      <el-table-column label="剩余天数" align="center" prop="lastDay">
        <template slot-scope="scope">
          <p>{{ scope.row.lastDay}}天</p>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改作业证书详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body  v-myDialogDrag>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <!-- <el-col :span="12">
            <el-form-item label="主表id" prop="parentId">
              <el-input v-model="form.parentId" placeholder="请输入主表id" :disabled="openDisabled" />
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span="12">
            <el-form-item label="序号" prop="xh">
              <el-input v-model="form.xh" placeholder="请输入序号" :disabled="openDisabled" />
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="部门" prop="deptName">
              <el-input v-model="form.deptName" placeholder="请输入部门" :disabled="openDisabled" />
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="特殊工种证件" prop="tsgzzj">
              <el-input v-model="form.tsgzzj" placeholder="请输入特殊工种证件" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发证机关" prop="fzjg">
              <el-input v-model="form.fzjg" placeholder="请输入发证机关" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件时效" prop="zjsx">
              <el-input v-model="form.zjsx" placeholder="请输入证件时效" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证书编号" prop="zsbh">
              <el-input v-model="form.zsbh" placeholder="请输入证书编号" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="初领证日期" prop="firstGetDate">
              <el-date-picker clearable size="small" v-model="form.firstGetDate" type="date" value-format="yyyy-MM-dd"
                placeholder="选择初领证日期" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="换证周期" prop="changeTerm">
              <el-input v-model="form.changeTerm" placeholder="请输入换证周期" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="复审周期" prop="validateTerm">
              <el-input v-model="form.validateTerm" placeholder="请输入复审周期" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上次复审日期" prop="lastValidateDate">
              <el-date-picker clearable size="small" v-model="form.lastValidateDate" type="date"
                value-format="yyyy-MM-dd" placeholder="选择上次复审日期" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下次复审日期" prop="nextValidateDate">
              <el-date-picker clearable size="small" v-model="form.nextValidateDate" type="date"
                value-format="yyyy-MM-dd" placeholder="选择下次复审日期" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="是否过期" prop="expiredFlag">
              <el-input v-model="form.expiredFlag" placeholder="请输入是否过期" :disabled="openDisabled" />
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/equipment/tzsb/zyzsInfo";

  export default {
    name: "Info",
    data() {
      return {
        //弹窗是否禁止编辑
        openDisabled: true,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 作业证书详情表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 50,
          // xh: null,
          name: null,
          deptName: null,
          tsgzzj: null,
          fzjg: null,
          zjsx: null,
          zsbh: null,
          firstGetDate: null,
          changeTerm: null,
          validateTerm: null,
          lastValidateDate: null,
          nextValidateDate: null,
          parentId: this.$route.query.parentId,
          expiredFlag: this.$route.query.expiredFlag,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {

          name: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          tsgzzj: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          fzjg: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          zjsx: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          zsbh: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          firstGetDate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],

          changeTerm: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          validateTerm: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          lastValidateDate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          nextValidateDate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          // remark: [
          //   { required: true, message: '不能为空', trigger: 'blur' }
          // ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询作业证书详情列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          parentId: null,
          // xh: null,
          name: null,
          deptName: null,
          tsgzzj: null,
          fzjg: null,
          zjsx: null,
          zsbh: null,
          firstGetDate: null,
          changeTerm: null,
          validateTerm: null,
          lastValidateDate: null,
          nextValidateDate: null,
          expiredFlag: null,
          remark: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.openDisabled = false;
        this.open = true;
        this.title = "添加作业证书详情";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.openDisabled = false;
        const id = row.id || this.ids
        getInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改作业证书详情";
        });
      },

      cellStyle({ row, column, rowIndex, columnIndex }) {
        if (row.lastDay == "0") {
          return "color:red;!important";
        }
        return "";
      },

      /** 查看按钮 */
      handleView(row) {
        this.reset();
        this.openDisabled = true;
        const id = row.id || this.ids
        getInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "查看作业证书详情";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateInfo({...this.form, parentId: this.$route.query.parentId}).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              const rLoading = this.openLoading();
              addInfo({...this.form, parentId: this.$route.query.parentId}).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                rLoading.close();
                this.getList();
              }).catch((error) => {
                rLoading.close();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除作业证书详情编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => { });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('zyzs/info/export', {
          ...this.queryParams
        }, '作业证书详情' + this.parseTime(new Date) + '.xlsx')
      }
    }
  };
</script>
